﻿using Kenly.DBFramework.Gateway;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
using System;
using System.Runtime;

using Kenly.DBFramework.TestModel.Purchasing;

namespace Kenly.DBFramework.Tests
{

    /// <summary>
    ///这是 ViewGatewayTest 的测试类，旨在
    ///包含所有 ViewGatewayTest 单元测试
    ///</summary>
    [TestClass()]
    public class ViewGatewayTest
    {
        private TestContext testContextInstance;

        /// <summary>
        ///获取或设置测试上下文，上下文提供
        ///有关当前测试运行及其功能的信息。
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region 附加测试属性
        // 
        //编写测试时，还可使用以下属性:
        //
        //使用 ClassInitialize 在运行类中的第一个测试前先运行代码
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //使用 ClassCleanup 在运行完类中的所有测试后再运行代码
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}

        //使用 TestInitialize 在运行每个测试前先运行代码
        [TestInitialize()]
        public void MyTestInitialize()
        {
        }

        //使用 TestCleanup 在运行完每个测试后运行代码
        [TestCleanup()]
        public void MyTestCleanup()
        {

        }

        #endregion


        /// <summary>
        ///DistinctVendorNames 的测试
        ///</summary>
        [TestMethod()]
        public void DistinctVendorNamesTest()
        {
            DistinctVendorNames();
        }

        private static bool DistinctVendorNames()
        {
            string msg="Vendor.DistinctVendorNames did not return expected value.";

            List<string> actual = Vendor.DistinctVendorNames();

            for (int i = 0; i < actual.Count - 1; i++)
            {
                Assert.IsTrue(actual[i] != actual[i + 1],msg +" has duplicate items.");
                Assert.IsTrue(actual[i].CompareTo(actual[i + 1])<0, msg + " with wrong order.");
            }

            return true;
        }

        /// <summary>
        /// 
        /// </summary>
        [TestMethod()]
        public void DistinctVendorNamesDescendTest()
        {
            string msg = "Vendor.DistinctVendorNamesDescend did not return expected value.";

            List<string> actual = Vendor.DistinctVendorNamesDescend();

            for (int i = 0; i < actual.Count - 1; i++)
            {
                Assert.IsTrue(actual[i] != actual[i + 1], msg + " has duplicate items.");
                Assert.IsTrue(actual[i].CompareTo(actual[i + 1]) > 0, msg + " with wrong order.");
            }
        }

        /// <summary>
        ///DistinctVendorNamesInvalid 的测试
        ///</summary>
        [TestMethod()]
        public void DistinctVendorNamesInvalidTest()
        {
            List<int> actual = Vendor.DistinctVendorNamesInvalid();

            Assert.IsTrue(actual.Count == 0, "Vendor.DistinctVendorNamesInvalid did not return expected value.");
        }

        /// <summary>
        /// 
        /// </summary>
        [TestMethod()]
        public void VendorIdTest()
        {
            Vendor vendor = new Vendor();

            ValidateEntityId(vendor);

            vendor.VendorId = 1;

            ValidateEntityId(vendor);
        }

        private static void ValidateEntityId(Vendor vendor)
        {
            Assert.IsTrue(vendor.EntityId.ToString() == vendor.VendorId.ToString(),
                "Vendor.VendorId did not return expected value.");
        }

        /// <summary>
        /// 
        /// </summary>
        [TestMethod()]
        public void PrimaryKeyTest()
        {
            Vendor vendor = new Vendor();

            ValidatePrimaryKey(vendor);

            vendor.AccountNumber = "12345678";

            ValidatePrimaryKey(vendor);
        }

        private static void ValidatePrimaryKey(Vendor vendor)
        {
            string msg = "Vendor.PrimaryKey did not return expected value.";

            if (vendor.AccountNumber == null)
            {
                Assert.IsTrue(vendor.PrimaryKey == null,
                    msg + "vendor.AccountNumber==null");
            }
            else
            {
                Assert.IsTrue(vendor.PrimaryKey.ToString() == vendor.AccountNumber,
                    msg + "vendor.AccountNumber==" + vendor.AccountNumber);
            }
        }

      
    }
}
